import React from "react";
import {
  ActivityIndicator, StyleSheet, Text, View,
} from "react-native";
import PropTypes from "prop-types";

import { FontSize, ScreenHeight } from "../../common/index";

const Loading = props => {
  const {
    loadingHint, containerBgColor, top, indicatorColor, hintStyle,
  } = props;
  const hasHint = loadingHint && loadingHint !== "";
  return (
    <View style={[styles.loading, { backgroundColor: containerBgColor, top }]}>
      <ActivityIndicator color={indicatorColor} />
      {hasHint ? <Text style={[styles.loadingTitle, hintStyle]}>{loadingHint}</Text> : null}
    </View>
  );
};
Loading.propsTypes = {
  loadingHint: PropTypes.string,
  hintStyle: PropTypes.any,
  indicatorColor: PropTypes.string,
  containerBgColor: PropTypes.string,
  top: PropTypes.number,
};

Loading.defaultProps = {
  loadingHint: "加载中……",
  indicatorColor: "white",
  containerBgColor: "rgba(102,102,102, 0.9)",
  top: ScreenHeight / 3,
};

const styles = StyleSheet.create({
  loading: {
    height: 80,
    width: 100,
    borderRadius: 10,
    justifyContent: "center",
    alignItems: "center",
    alignSelf: "center",
  },
  loadingTitle: {
    marginTop: 10,
    fontSize: FontSize.SIZE_14,
    color: "white",
  },
});
export default Loading;
